package com.ajax.Dao;

import com.ajax.entity.User;

import javax.swing.text.DefaultEditorKit;
import java.util.*;
public class UserDAO extends BasicDAO<User>{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] t = s.split(" ");
        HashMap<String, Integer> map = new HashMap<>();

        List<DC> dc = new ArrayList<DC>();
        for (int i = 0; i < t.length; i++) {
            if(map.containsKey(t[i])){
                Integer q = map.get(t[i]);
                map.put(t[i],q+1);
            }else{
                map.put(t[i],1);
            }
        }
        map.forEach((key,value)->{
            dc.add(new DC(key,value));
        });
        Collections.sort(dc);
       dc.forEach((m)->{
           System.out.println(m.name+" "+m.id);
        });
    }

}
 class DC implements Comparable<DC>{
    public  String name;
    public  int id;

    public DC(String name, int id) {
        this.name = name;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }



    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DC dc = (DC) o;
        return Objects.equals(name, dc.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

     @Override
     public int compareTo(DC o) {
        if(o.id!=this.id) {
            return o.id - this.id;
        }
         for (int i = 0; i <Math.min(this.name.length(),o.name.length()); i++) {
             return this.name.charAt(i)-o.name.charAt(i);
         }
        return 0;
    }
 }
